package player.ui.dialog;

import java.awt.Color;
import java.awt.Component;
import java.awt.image.BufferedImage;
import java.util.ArrayList;

import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JTable;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.TableColumn;

import player.PS;
import player.ThumbManage;
import player.mplayer.MediaInfo;
import player.ui.playlist.PlayListModel;

public class MyTableCellRenderer1  extends  DefaultTableCellRenderer{
	private static final long serialVersionUID = -8384873735466373081L;
	PlayListModel pm;
	public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
		boolean isPlaying=false;
		pm=(PlayListModel) table.getModel();
		
		BufferedImage[] bis=null;
		Color bgColor=null;
		if(row%2 == 0) 
			bgColor=(new Color(240,251,254)); 
	        else if(row%2 == 1) 
	        	bgColor=(new Color(230,231,254));
		int rh=0;
		if(!isSelected){
			rh=MyTableCellRenderer0.rowHeight1;
		}else{
			rh=MyTableCellRenderer0.rowHeight2;
		}
		JComponent bt=new JLabel("");
		    if(value!=null){
		    	if(value.getClass().equals(MediaInfo.class)){
		    		MediaInfo mf=null;
		    		TableColumn column2 = table.getColumnModel().getColumn(column);
				    if(column2.getIdentifier().equals(PlayListModel.n_img)){
				    	mf=(MediaInfo)value;
				    	if(mf!=null&pm.nowPlayMedia!=null){
				    		if(mf.mediaPath.equals(pm.nowPlayMedia.mediaPath)){
					    		isPlaying=true;
					    	}
				    	}
				    		
				    	if(!ThumbManage.containImg(mf.mediaPath)){
				    		ThumbManage.tryMplayImg(mf.mediaPath);
				    	}else{
				    		ArrayList<BufferedImage> list=new ArrayList<BufferedImage>();
				    		for(int i=0;i<7;i++){
				    			BufferedImage bi=ThumbManage.getImg(mf.mediaPath,i);
				    			if(bi!=null){
				    				list.add(ThumbManage.getImg(mf.mediaPath,i));
				    			}else{
				    				break;
				    			}
				    		}
				    		bis=new BufferedImage[list.size()];
				    		for(int i=0;i<bis.length;i++){
				    			bis[i]=list.get(i);
				    		}
				    	}
				    	bt=new ImgPanel(bis,bgColor,isSelected);
				    } 
		    	}
		    }
		    
		    
		    return bt;
		    
		  }
}
